<template>
	<app-layout>
		<app-banner></app-banner>
		<view class="home-hot">
			<app-title text="推荐藏品" :width="64"></app-title>
			<view class="hot-prod" @click="$tool.navigateTo(`/pages/home/detail?id=${hotProd.id}`)">
				<view class="prod-img">
					<image class="img" :src="hotProd.pictureUrl" mode=""></image>
				</view>
				<view class="prod-info">
					<view class="name">{{hotProd.worksName}}</view>
					<view class="other">
						<text class="number">#{{hotProd.worksNum}}</text> <text class="price">￥{{hotProd.price}}</text>
					</view>
					<view class="bay"></view>
				</view>
			</view>
		</view>
		<view class="home-find">
			<app-title text="发现藏品" :width="64"></app-title>
			<view class="find-box">
				<view class="box-item" v-for="item in findProds" :key="item.id"
					@click="$tool.navigateTo(`/pages/home/detail?id=${item.id}`)">
					<view class="prod-img">
						<image class="img" :src="item.subPctureUrl" mode=""></image>
					</view>
					<view class="prod-info">
						<view class="name">{{item.worksName}}</view>
						<view class="other">
							<text class="number">#{{item.worksNum}}</text> <text class="price">￥{{item.price}}</text>
						</view>
						<view class="bay"></view>
					</view>
				</view>
			</view>
			<uni-load-more :contentText="contentText" @clickLoadMore="onClickLoadMore" :status="findStatus">
			</uni-load-more>
		</view>
	</app-layout>
</template>

<script>
	import {
		getBanner,
		getWorksPage,
		getFrontPage
	} from "../../request/home-api.js"
	export default {
		data() {
			return {
				// 轮播图 数据
				banners: [],
				// 推荐藏品 数据
				hotProd: {},
				// 发现藏品 数据
				findProds: [],
				// 发现藏品 查询参数
				findParam: {
					condition: {
						sortRule: 'SELL',
						sortType: 'ASC'
					},
					pageNum: 0,
					pageSize: 10
				},
				// 没有更多了
				isNoMore: false,
				// 加载状态
				findStatus: 'more',
				// 各状态文字说明
				contentText: {
					contentdown: "点击加载更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				}
			}
		},
		created() {
			this.getHotProd()
			this.getFindProds()
			this.$emit('update')
		},
		methods: {
			// 点击加载更多
			onClickLoadMore() {
				if (!this.isNoMore) {
					this.getFindProds()
				}
			},

			// 获取推荐作品
			async getHotProd() {
				try {
					let {
						code,
						message,
						data
					} = await getFrontPage()
					if (code === 200) {
						this.hotProd = data
					} else {
						uni.showToast({
							title: message,
							icon: 'error'
						})
					}
				} catch (err) {
					this.$tool.showErr(err)
				}
			},

			// 获取发现作品
			async getFindProds() {
				this.findStatus = 'loading'
				this.findParam.pageNum += 1
				try {
					let {
						code,
						message,
						data
					} = await getWorksPage(this.findParam)
					if (code === 200) {
						if (this.findParam.pageNum <= data.totalPage) {
							this.isNoMore = false
							this.findProds.push(...data.list)
							this.findStatus = 'more'
						} else {
							this.isNoMore = true
							this.findStatus = 'noMore'
						}
					} else {
						this.findStatus = 'more'
						uni.showToast({
							title: message,
							icon: 'error'
						})
					}
				} catch (err) {
					this.findStatus = 'more'
					this.$tool.showErr(err)
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.home-hot {
		width: 100%;
		margin: 20rpx 0 40rpx 0;

		.hot-prod {
			width: 700rpx;
			height: 800rpx;
			position: relative;
			background: linear-gradient(218deg, #3E454D 0%, #26252A 100%);
			box-shadow: -6rpx -6rpx 16rpx 0px rgba(70, 75, 86, 0.54), 6rpx 6rpx 16rpx 0px rgba(0, 0, 0, 0.83);
			border-radius: 32rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			margin: 0 auto;
			padding: 10rpx;
			margin-top: 40rpx;

			.prod-img {
				width: 680rpx;
				height: 634rpx;
				border-radius: 24rpx;
				overflow: hidden;
				background-color: #474A51;

				.img {
					width: 680rpx;
					height: 634rpx;
				}
			}

			.prod-info {
				.bay {
					width: 70rpx;
					height: 70rpx;
					right: 20rpx;
					top: 40rpx;
				}
			}

		}
	}

	.home-find {
		width: 100%;
		height: auto;

		.find-box {
			margin: 20rpx 0;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.box-item {
				width: 334rpx;
				height: 500rpx;
				margin-bottom: 40rpx;
				background: linear-gradient(218deg, #3E454D 0%, #26252A 100%);
				box-shadow: -6rpx -6rpx 16rpx 0px rgba(70, 75, 86, 0.54), 6rpx 6rpx 16rpx 0px rgba(0, 0, 0, 0.83);
				border-radius: 32rpx;

				.prod-img {
					width: 334rpx;
					height: 334rpx;
					overflow: hidden;
					border-radius: 32rpx;
					background-color: #474A51;

					.img {
						width: 334rpx;
						height: 334rpx;
					}
				}

			}
		}
	}

	.prod-info {
		width: 100%;
		min-height: 42px;
		margin-top: 30rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding: 0 20rpx;
		position: relative;
		color: #BFCBCD;
		font-family: SourceHanSansCN-Bold, SourceHanSansCN;

		.name {
			width: 300rpx;
			font-size: 32rpx;
			font-weight: bold;
			line-height: 48rpx;
			margin-bottom: 20rpx;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}

		.other {
			width: 100%;
			font-size: 24rpx;
			font-weight: 400;
			color: #BFCBCD;
			line-height: 18px;
			margin-bottom: 28rpx;
			display: flex;
			align-items: center;

			.number {
				display: inline-block;
				min-width: 50rpx;
				height: 50rpx;
				text-align: center;
				line-height: 50rpx;
				max-height: 50rpx;
				border: 2rpx solid #FFBD47;
				border-radius: 16rpx 0 0 16rpx;
				padding: 0 8rpx;
			}

			.price {
				display: inline-block;
				height: 50rpx;
				background: #FFBD47;
				font-size: 24rpx;
				font-family: SourceHanSansCN-Bold, SourceHanSansCN;
				font-weight: bold;
				line-height: 50rpx;
				color: #1B1D24;
				padding: 0 10rpx;
				border: 2rpx solid #FFBD47;
				border-radius: 0 16rpx 16rpx 0;
			}
		}

		.bay {
			width: 50rpx;
			height: 50rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: absolute;
			right: 20rpx;
			top: 70rpx;
			box-shadow: -12rpx -12rpx 24rpx 0px rgba(66, 69, 76, 0.54), 12rpx 12rpx 24rpx 0px rgba(0, 0, 0, 0.83);
			border: 2rpx solid #FFBD47;
			border-radius: 50%;
			background: $common-right-url no-repeat;
			background-size: 60% 60%;
			background-position: center center;
			background-color: #1B1D24;
		}
	}
</style>
